import { Component } from '@angular/core';
import { Bus } from './bus';

import { OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { BusService } from './bus.service';

@Component({
  selector: 'my-buss',
  templateUrl: './bus.component.html'
})

export class BusComponent implements OnInit {
  ngOnInit() {
    this.getBuss();
  }

  buss: Bus[];
  selectedBus: Bus;

  onSelect(bus: Bus) { this.selectedBus = bus; }
  onNew() { 
    this.selectedBus = new Bus(); 
    let loginUsercarrierID = localStorage.getItem('loginUsercarrierID');
    this.selectedBus.carrier_id = parseInt(loginUsercarrierID);
  }

  constructor(
    private router: Router,
    private busService: BusService) {
  }



  getBuss() {
    if(localStorage.getItem('loginUsercarrierID') == '0' || localStorage.getItem('loginUsercarrierID') == null){
      this.busService.getBuss().then(buss => this.buss = buss);
    }else{
      this.busService.getBussByCarrierID(localStorage.getItem('loginUsercarrierID')).then(buss => this.buss = buss);
    }

  }
}
